package com.luguz.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luguz.pojo.User;
import com.luguz.service.IUserService;
import com.luguz.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author guz
 * @since 2022-02-25
 */
@RestController
public class UserController {
    @Autowired
    private UserServiceImpl userService;
    @GetMapping("/user/{id}")
    public Object getUserById(@PathVariable("id") Integer id){
        return userService.getById(id);
    }
    @GetMapping("/users")
    public Object getUsers(){
        return userService.query();
    }
//  分页
    @GetMapping("/search/{pageNo}/{pageSize}")
    public Object findByPage(@PathVariable Integer pageNo,
                             @PathVariable Integer pageSize){

        //根据条件分页查询
        IPage<User> page = new Page<>(pageNo, pageSize);
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id");
        IPage<User> userIPage = userService.page(page, wrapper);
        return userIPage;
    }
}
